import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getLoginUserUsingGet } from '@/api/userController.ts'

export const useLoginUserStore = defineStore('loginUser', () => {
  const loginUser = ref<API.LoginUserVO>({
    userName: '未登录',
  })

  function setLoginUser(user: never) {
    loginUser.value = user
  }

  /**
   * 远程获取登录用户
   */
  async function getLoginUser() {
    // return await userUsingGet()
    const res = await getLoginUserUsingGet()
    if (res.data.code == 0 && res.data.data) {
      loginUser.value = res.data.data
    }
  }

  // 删除登录用户
  function deleteLoginUser() {
    loginUser.value = {  }
  }

  return { loginUser, setLoginUser, getLoginUser, deleteLoginUser }
})
